<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改代理商扣款规则')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-agentDeductions-edit" th:object="${agentDeductions}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">服务商编号：</label>
            <div class="col-sm-8">
                <input name="agentNum" th:field="*{agentNum}" id="xagentNum" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">服务商名称：</label>
            <div class="col-sm-8">
                <input name="agentName" th:field="*{agentName}" onclick="selectAgent()"  class="form-control" id="xagentName" type="text" required readonly>
                <i class="fa fa-search" style="margin-top: -22px;margin-right:3px;float:right;"></i>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">激活类型 ：</label>
            <div class="col-sm-8">
                <select name="deductionType" onchange="terminalShow(this)" id="deductionType" th:field="*{deductionType}" class="form-control m-b">
                    <option value="2">伪激活</option>
                    <option value="1">机具扣款</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">机具类型：</label>
            <div class="col-sm-8">
                <select id="posType" name="posType" class="form-control noselect2 selectpicker" th:field="*{posType}" th:with="type=${@dict.getType('terminal_type')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div id="terminalShow" th:hidden="(*{deductionType} == 1)">
            <div class="form-group">
                <label class="col-sm-3 control-label">sn号：</label>
                <div class="col-sm-8">
                    <input name="sn" id="sn" th:field="*{sn}" class="form-control" onclick="selectPos()" type="text" required readonly>
                    <i class="fa fa-search" style="margin-top: -22px;margin-right:3px;float:right;"></i>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">机具数量：</label>
                <div class="col-sm-8">
                    <input name="posNumber" id="count" th:field="*{posNumber}" class="form-control" type="text" readonly>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">扣款金额（<span id="dan">单</span>元）：</label>
            <div class="col-sm-8">
                <input name="deductionMoney" class="form-control" type="text" id="deductionMoney" th:field="*{deductionMoney}" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">扣款比例（%）：</label>
            <div class="col-sm-8">
                <input name="ratio" th:field="*{ratio}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">扣款用途：</label>
            <div class="col-sm-8">
                <input name="note" th:field="*{note}" id="note" class="form-control" type="text" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "finance/agentDeductions";
    $("#form-agentDeductions-edit").validate({
        focusCleanup: true
    });

    $("input[name='date']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function submitHandler() {
        if($("#deductionMoney").val() <= 0){
            $.modal.alertWarning("扣款金额必须大于0！");
            return;
        }
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-agentDeductions-edit').serialize());
        }
    }

    function selectAgent() {
        // var url =ctx + "terminal/record"+ "/selectAgentInfo";
        var url =prefix + "/selectAgentInfo2";
        $.modal.open("选择服务商" , url, '700');
    }

    function selectPos() {
        if($("#xagentNum").val() == ""){
            $.modal.alertWarning("请先填写服务商！");
            return;
        }
        var url =prefix+ "/selectPosInfo?pos_type="+$("#posType").val()+"&agent_num="+$("#xagentNum").val()+"&sns="+$("#sn").val()
        $.modal.open("选择sn机具" , url, '700');
    }

    function terminalShow(obj) {
        if(obj.value == 1){
            $("#terminalShow").hide();
            $("#dan").text("总")
            $("#note").val("机具尾款")
            $("#deductionMoney").val("")
            $("#deductionMoney").removeAttrs("readonly")
        }else {
            $("#terminalShow").show();
            $("#dan").text("单")
            $("#note").val("伪激活机具尾款")
            $("#deductionMoney").val("120")
            $("#deductionMoney").attr("readonly","readonly")
        }
    }
    if($("#deductionType").val() == 1){
        $("#note").val("机具尾款")
        $("#deductionMoney").removeAttrs("readonly")
    }else{
        $("#note").val("伪激活机具尾款")
        $("#deductionMoney").val("120")
        $("#deductionMoney").attr("readonly","readonly")
    }

</script>
</body>
</html>